#ifndef BEZIER_CURVE_HPP  
#define BEZIER_CURVE_HPP  
  
#include <vector>  
#include <functional>  
#include <utility>  
#include <cmath>  
  
std::function<std::pair<double,double>(double)> Bezier_curves(const std::pair<double,double>& p,const std::pair<double,double>& p1, std::pair<double,double>& dy, std::pair<double,double>& dy1) {  
  return [p, p1, dy, dy1](double t) -> std::pair<double,double> {  
    std::pair<double, double> d0, q0, q1, q2, q3;     
    if(t > 1 || t < 0)  
      return std::make_pair(0.0, 0.0);  
    else {  
      
      q0 = p;  
      q1.first = 1./3 * dy.first + p.first;  
      q1.second = 1./3 * dy.second + p.second; 
      q2.first = p1.first - 1./3 * dy1.first;  
      q2.second = p1.second - 1./3 * dy1.second;  
      q3 = p1;  
  
      double b0, b1, b2, b3;  
      b0 = pow(1 - t, 3);  
      b1 = 3. * t * pow(1 - t, 2);  
      b2 = 3. * t * t * (1 - t);  
      b3 = pow(t, 3);  
  
      double x, y;  
      x = b0 * q0.first + b1 * q1.first + b2 * q2.first + b3 * q3.first;  
      y = b0 * q0.second + b1 * q1.second + b2 * q2.second + b3 * q3.second;  
      return std::make_pair(x, y);  
    }  
  };  
}  
  
#endif  

